//package com.lsyw.intergrate.config.rabbitMq;
//
//import com.alibaba.fastjson.JSONObject;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.lsyw.intergrate.entity.Hbdtsj;
//import com.lsyw.intergrate.entity.Hbjw;
//import com.lsyw.intergrate.entity.Hbzy;
//import com.lsyw.intergrate.service.HbdtsjService;
//import com.lsyw.intergrate.service.HbjwService;
//import com.lsyw.intergrate.service.HbzyService;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.support.AmqpHeaders;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.messaging.MessageHeaders;
//import org.springframework.messaging.handler.annotation.Header;
//import org.springframework.messaging.handler.annotation.Headers;
//import org.springframework.stereotype.Component;
//
//@Component
//@Slf4j
//@RabbitListener(queues = {TopicRabbitConfig.TOPIC_QUEUE_NAME})
//public class TopicHandler {
//
//    @Autowired
//    private HbdtsjService hbdtsjService;
//    @Autowired
//    private HbjwService hbjwService;
//    @Autowired
//    private HbzyService hbzyService;
//
//
//    @RabbitHandler
//    public void processByteMsg(@Headers MessageHeaders headers, byte[] msgPayload) {
//        String msg = new String(msgPayload);
//        log.info("TopicHandler1收到消息:{},exchange:{},routingKey:{},queue:{}",
//                msg, headers.get("amqp_receivedExchange"),
//                headers.get("amqp_receivedRoutingKey"),
//                headers.get("amqp_consumerQueue"));
//    }
//
//    @RabbitHandler
//    public void processStringMsg(@Headers MessageHeaders headers, Channel channel, String msg,
//                                 @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag,
//                                 @Header(AmqpHeaders.CONSUMER_TAG) String consumerTag) throws Exception {
//        log.info("TopicHandler2收到消息:{},exchange:{},routingKey:{},queue:{}",
//                msg, headers.get("amqp_receivedExchange"),
//                headers.get("amqp_receivedRoutingKey"),
//                headers.get("amqp_consumerQueue"));
//        channel.basicAck(deliveryTag, false);
//        JSONObject json = JSONObject.parseObject(msg);
//        String dataSource = json.getString("dataSource");
//        String dataType = json.getString("dataType");
//        JSONObject flightmeta = json.getJSONObject("flightmeta");
//        JSONObject expression = json.getJSONObject("expression");
//        if ("FLOP".equals(dataSource)) {
//            Hbdtsj hbdtsj = JSONObject.toJavaObject(expression, Hbdtsj.class);
//            //航班信息
//            if ("INSERT".equals(dataType)) {
//                hbdtsjService.save(hbdtsj);
//            } else if ("UPDATE".equals(dataType)) {
//                hbdtsjService.update(hbdtsj,new QueryWrapper<Hbdtsj>().eq("HBROWID",flightmeta.getString("HBROWID")));
//            } else if ("DELETE".equals(dataType)) {
//                hbdtsjService.remove(new QueryWrapper<Hbdtsj>().eq("HBROWID",flightmeta.getString("HBROWID")));
//            }
//        } else if ("FLTA".equals(dataSource)) {
//            Hbzy hbzy = JSONObject.toJavaObject(expression, Hbzy.class);
//            //航班信息
//            if ("INSERT".equals(dataType)) {
//                hbzyService.save(hbzy);
//            } else if ("UPDATE".equals(dataType)) {
//                hbzyService.update(hbzy,new QueryWrapper<Hbzy>().eq("HBROWID",flightmeta.getString("HBROWID")));
//            } else if ("DELETE".equals(dataType)) {
//                hbzyService.remove(new QueryWrapper<Hbzy>().eq("HBROWID",flightmeta.getString("HBROWID")));
//            }
//        } else if ("FLST".equals(dataSource)) {
//            Hbjw hbjw = JSONObject.toJavaObject(expression, Hbjw.class);
//            //航班信息
//            if ("INSERT".equals(dataType)) {
//                hbjwService.save(hbjw);
//            } else if ("UPDATE".equals(dataType)) {
//                hbjwService.update(hbjw,new QueryWrapper<Hbjw>().eq("HBROWID",flightmeta.getString("HBROWID")));
//            } else if ("DELETE".equals(dataType)) {
//                hbjwService.remove(new QueryWrapper<Hbjw>().eq("HBROWID",flightmeta.getString("HBROWID")));
//            }
//        }
//        //拒绝消息, requeue为true会重入队列, 消息就会一直接受
//        //channel.basicNack(deliveryTag,false,false);
//        //channel.basicCancel(consumerTag);
//    }
//
//}
//
